﻿
Public Class frmFullscreen
    Public _controls As ucControls
    Public _window As ucWindow
    Private _hasInit As Boolean = False
   

    Public Sub ExitFullscreen()
        frmMain.pnWindow.Controls.Add(_window)
        frmMain.pnControls.Controls.Add(_controls)
        _controls.Size = frmMain.pnControls.Size
        _window.Size = frmMain.pnWindow.Size
        _controls.ToggleFullscreen = False
        Me.TopLevel = False
        frmMain.TopLevel = True
        Me.Hide()
    End Sub

    Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
        '' Restore window when the user presses Escape
        If keyData = Keys.Escape Then
            ExitFullscreen()
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function

    Private Sub MyForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        'If e.CloseReason = CloseReason.UserClosing = True Then
        'e.Cancel = True
        'ExitFullscreen()
        'Else
        e.Cancel = False
        'End If
    End Sub

    Public Sub Init(controlsinstance As ucControls, windowinstance As ucWindow)
        _controls = controlsinstance
        _window = windowinstance

        Me.TopLevel = True
        frmMain.TopLevel = False
        Me.Show()
        Me.Bounds = Screen.FromControl(frmMain).Bounds

        _hasInit = True
        Me.pnControls.Controls.Add(controlsinstance)
        _controls.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        _controls.Size = New System.Drawing.Size(550, 90)
        Me.pnWindow.Controls.Add(windowinstance)
        _window.Dock = DockStyle.Fill
        _controls.ToggleFullscreen = True
    End Sub

    Private Sub frmTimer_Tick(sender As System.Object, e As System.EventArgs) Handles frmTimer.Tick
        If _controls.ToggleFullscreen = True Then
            pnControls.Visible = False
            frmTimer.Stop()
        End If
    End Sub

    Private Sub GlobalEventProvider1_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles GlobalEventProvider1.MouseMove
        If _hasInit = True Then
            If _controls.ToggleFullscreen = True Then
                pnControls.Visible = True
                If _controls.Mouseactive = True Then
                    frmTimer.Stop()
                ElseIf _controls.Mouseactive = False Then
                    frmTimer.Start()
                End If
            End If
        End If
    End Sub

    Private Sub frmFullscreen_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        pnControls.Visible = False
    End Sub
End Class